﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace ThoiTrangT2B
{
    public partial class UCMenu : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            LoadMenu();
        }

        protected void LoadMenu()
        {
            ltrMenu.Text = "";
            string sql = "SELECT * FROM dbo.tblT2BMenu where ParentID is null";
            DataTable dt = SqlHelper.ExecuteDataTable(CommandType.Text, sql);
            string TenDM;
            int MenuID;
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                MenuID = Convert.ToInt32(dt.Rows[i]["ID"]);
                TenDM = dt.Rows[i]["Ten"].ToString();
                ltrMenu.Text += "<li><a href='XemSanPham.aspx?cID=" + MenuID + "'>" + TenDM + "</a>";
                LoadChild(MenuID);
                ltrMenu.Text += "</li>";
            }
        }

        protected void LoadChild(int pID)
        {
            ltrMenu.Text += "<ul>";
            string sql = "SELECT * FROM dbo.tblT2BMenu WHERE ParentID = " + pID;
            DataTable dt = SqlHelper.ExecuteDataTable(CommandType.Text, sql);
            string TenDM;
            int MenuID;
            string Image;
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                MenuID = Convert.ToInt32(dt.Rows[i]["ID"]);
                TenDM = dt.Rows[i]["Ten"].ToString();
                Image = dt.Rows[i]["Image"].ToString();
                ltrMenu.Text += "<li style='background: url(../" + Image + ") no-repeat 120px 40px;height:146px !important'>";
                ltrMenu.Text += "<a href='XemSanPham.aspx?cID=" + MenuID + "'>" + TenDM + "</a>";
                LoadSubChild(MenuID);
                ltrMenu.Text += "</li>";
            }
            ltrMenu.Text += "</ul>";
        }

        protected void LoadSubChild(int pID)
        {
            ltrMenu.Text += "<ul>";
            string sql = "SELECT * FROM dbo.tblT2BMenu WHERE ParentID = " + pID;
            DataTable dt = SqlHelper.ExecuteDataTable(CommandType.Text, sql);
            string TenDM;
            int MenuID;
            string Image;
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                MenuID = Convert.ToInt32(dt.Rows[i]["ID"]);
                TenDM = dt.Rows[i]["Ten"].ToString();
                Image = dt.Rows[i]["Image"].ToString();
                ltrMenu.Text += "<li><a href='XemSanPham.aspx?cID=" + MenuID + "'>" + TenDM + "</a></li>";
                LoadSubChild(MenuID);
                ltrMenu.Text += "</li>";
            }
            ltrMenu.Text += "</ul>";
        }
    }
}